Skip to content

fix(tests): make integration tests pass on macOS#1091

Merged
Brutus5000 merged 3 commits into
developfrom
fix/macos-integration-tests
Jun 13, 2026
Merged

fix(tests): make integration tests pass on macOS#1091
Brutus5000 merged 3 commits into
developfrom
fix/macos-integration-tests

Conversation

@Brutus5000

@Brutus5000 Brutus5000 commented Jun 11, 2026

Copy link
Copy Markdown
Member

Summary

On macOS with KqueueSelector, asyncio.open_connection(...) returns before the server-side accept callback has registered the new connection in ctx.connections. Three tests in tests/integration_tests/test_servercontext.py race this scheduling difference — they pass on Linux CI but fail deterministically on macOS.

  • test_unexpected_exception — added await exhaust_callbacks() so the server task emits the "Exception in protocol" log before caplog.text is asserted.
  • test_drain_connections — poll ctx.connections until populated before calling drain_connections. Cannot use exhaust_callbacks inside @fast_forward: the outer ticker keeps rescheduling itself and the inner exhaust never exits.
  • test_connection_broken_external — same poll, otherwise next(iter(ctx.connections.values())) raised StopIteration.

No production code is changed. Full integration suite (tests/integration_tests) goes from 3 fail / 323 pass to 326 pass on macOS (Darwin 24.6.0, Python 3.13). Linux behavior is unchanged — the added waits are no-ops when the server task has already run.

Test plan

  • CI passes on Linux (no regression)
  • pipenv run py.test tests/integration_tests --mysql_database=faf passes on macOS

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Improved determinism and reliability of server connection handling tests by ensuring tests wait for active connections before proceeding, reducing flakiness.
    • Enhanced matchmaker-related tests to wait for expected queue information before validating boundary values, making validations more robust and stable in CI.

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Brutus5000, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 8 minutes and 13 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 20f66696-4d2a-43c4-947f-66fc67fc366e

📥 Commits

Reviewing files that changed from the base of the PR and between 43735df and 23bf026.

📒 Files selected for processing (2)
  • tests/integration_tests/test_servercontext.py
  • tests/integration_tests/test_teammatchmaker.py
📝 Walkthrough

Walkthrough

Tests updated to wait deterministically: server-context tests spin until ctx.connections is populated or drain pending callbacks before assertions; a teammatchmaker test waits for a specific matchmaker_info message containing tmm2v2.boundary_80s.

Changes

Integration test synchronization and message waiting

Layer / File(s) Summary
Server connection and callback synchronization
tests/integration_tests/test_servercontext.py
test_serverside_abort and test_drain_connections now spin-wait (while not ctx.connections: await asyncio.sleep(0)) until ctx.connections is non-empty. test_unexpected_exception now calls await exhaust_callbacks() immediately after opening the connection to drain async protocol callbacks before log assertions.
Matchmaker info message predicate
tests/integration_tests/test_teammatchmaker.py
test_info_message uses a predicate (tmm2v2_populated) with read_until to wait for a matchmaker_info message whose queues includes queue_name == "tmm2v2" and a non-empty boundary_80s entry.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I waited in the loop with care,
Till connections showed and logs were fair,
A message found with borders true,
Now tests behave — a tidy view!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of the PR: fixing integration tests to work on macOS. The changes directly address platform-specific timing issues that prevent tests from passing on macOS.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/macos-integration-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/integration_tests/test_servercontext.py`:
- Around line 94-95: The unbounded polling `while not ctx.connections: await
asyncio.sleep(0)` can hang tests; update both occurrences (around the blocks at
lines referencing ctx.connections) to use a bounded wait with a timeout (e.g.,
record a deadline or use asyncio.wait_for) and fail fast when the timeout
elapses (raise an AssertionError or call pytest.fail with a clear message
indicating server registration did not occur within the timeout). Ensure you
apply the same change to both occurrences so the test will time out
deterministically rather than hanging indefinitely.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: eb1d217b-1e55-49e2-9293-d6cea5a313da

📥 Commits

Reviewing files that changed from the base of the PR and between e36de71 and 7e4f1c3.

📒 Files selected for processing (1)
  • tests/integration_tests/test_servercontext.py

Comment thread tests/integration_tests/test_servercontext.py Outdated
@Brutus5000

Copy link
Copy Markdown
Member Author

Addressed CodeRabbit's actionable comment in 5c2831e — both while not ctx.connections spin loops now go through a wait_for_connection_registered(ctx) helper that bounds the wait to 1000 yields and raises AssertionError on exhaustion, so a regression in server-side connection registration fails fast instead of hanging the suite.

The remaining lint failures are pre-existing on develop and unrelated to this PR:

  • mypyserver/protocol/qdatastream.py:95 bytearray vs bytes mismatch. This file is untouched here.
  • pipenv-verifyPipfile.lock is out-of-date. The lockfile hash drift is on develop itself; my branch's Pipfile/Pipfile.lock match develop exactly (git diff origin/develop -- Pipfile Pipfile.lock is empty).

Happy to address either in a follow-up if you'd like them bundled.

Brutus5000 and others added 3 commits June 12, 2026 01:06
On macOS with KqueueSelector, `asyncio.open_connection` returns before
the server-side accept callback registers the connection in
`ctx.connections`. Three tests in test_servercontext.py raced this
scheduling difference and failed deterministically on macOS while
passing on Linux CI.

- test_unexpected_exception: yield via exhaust_callbacks so the server
  task emits the "Exception in protocol" log before caplog is checked.
- test_drain_connections / test_connection_broken_external: poll
  ctx.connections until populated before depending on it. exhaust_callbacks
  cannot be used inside @fast_forward — the outer ticker keeps
  rescheduling itself and the inner exhaust never exits.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
`matchmaker_info` is broadcast by the periodic `report_dirties` ticker.
On macOS the first broadcast after `game_matchmaking` could be the
startup one (queue dirty but no searcher → empty boundary), making the
[[300, 700]] assertion fail. Wait for a matchmaker_info where the
tmm2v2 queue actually carries a non-empty boundary before asserting.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Address CodeRabbit feedback: replace `while not ctx.connections` spin
loops with a helper that polls up to a fixed iteration count and raises
AssertionError on exhaustion, so tests fail fast instead of hanging if
the server never registers the connection.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Brutus5000 Brutus5000 force-pushed the fix/macos-integration-tests branch from 5c2831e to 23bf026 Compare June 11, 2026 23:06
@Brutus5000 Brutus5000 merged commit b6b1850 into develop Jun 13, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant